[Fix] Failed ASSET GPU backend selection test when running in an environment with CUDA #666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The unit test
test_asset_choose_backend_openclfailed when running in a system with a GPU and CUDA libraries available, generating the errorAssertionError: 'cuda' != 'cpu'.Interestingly, the test failed with or without PyCUDA installed in the environment, which is not the expected behavior. In a system without PyCUDA or OpenCL, it should always use the CPU backend.
It was detected that the utility function for CUDA capabilities detection
utils.get_cuda_capability_majorused the CUDA libraries in the system directly, which returns valid capabilities regardless of the availability of PyCUDA. The latter is required by the functions in ASSET when running CUDA GPU code. Therefore, the first fix in this PR modifies the function to return zero if PyCUDA is not available. It then uses PyCUDA instead of the libraries to detect if a GPU is available and accessible to use with the ASSET function.This was the behavior enforced when setting flags for the tests in
test_asset.py. Therefore, the flags are now set to use the utility functions.Finally, the failed
test_asset_choose_backend_openclwas implemented as a regression test to check the conditions where no GPU was available and no environmental variable flags were set, which in the past resulted in trying to use the OpenCL backend instead of the CPU. Therefore, in a CI runner with GPU/CUDA, the test is not intended to run, as the default behavior in Elephant is to use the CUDA GPU acceleration and, hence, the backend selection returned'cuda'correctly. Therefore, the second fix in the PR conditions the test execution on not having PyCUDA and a GPU.